package cn.wubo.swagger.controller;

import cn.wubo.swagger.entity.Book;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "book")
@Api(value = "图书", description = "图书的API", tags = "TestBookApi")
public class BookController {

    @ApiOperation(value = "获取图书", notes = "获取全部图书信息列表")
    @RequestMapping(value = {""}, method = RequestMethod.GET)
    public List<Book> getBooks() {
        List<Book> books = new ArrayList<Book>() {{
            add(new Book("111", "AAA"));
            add(new Book("222", "BBB"));
        }};
        return books;
    }

    @ApiOperation(value = "获取一本图书", notes = "根据id获取一本图书信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Book getOneBook(@RequestParam(value = "id") Long id) {
        return new Book("111", "AAA");
    }

    @ApiOperation(value = "创建图书", notes = "创建一本图书信息")
    @ApiImplicitParam(name = "book", value = "图书详细实体", required = true, dataType = "Book", paramType = "body")
    @RequestMapping(value = "createBook", method = RequestMethod.POST)
    public String createBook(@RequestBody Book book) {
        return "success name:" + book.getName() + " desc:" + book.getDesc();
    }
}
